<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全选全不选</title>
    <script type="text/javascript" src="../js/jquery-3.4.1.min.js"></script>
<!--    <script type="text/javascript" src="../js/jquery-1.4.1.min.js"></script>-->
    <script>
        $(function () {
            $("#all").click(function () {
                // 在1.4.1版本之后,对于表单元素,不允许使用attr,而是使用prop
                // $("input[type='checkbox']").attr("checked", $(this).attr("checked"))
                $("input[type='checkbox']").prop("checked", $(this).prop("checked"))
            });
        })
    </script>
</head>
<body>
<table border="1">
    <tr>
        <th><input type="checkbox" id="all">全选</th>
        <th>学号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
        <th>操作</th>
    </tr>
    <tr>
        <td><input type="checkbox" name="students"></td>
        <td>1</td>
        <td>admin</td>
        <td>18</td>
        <td>男</td>
        <td>
            <a href="javascript:;">修改</a>
            <a href="javascript:;">删除</a>
        </td>
    </tr>
    <tr>
        <td><input type="checkbox" name="students"></td>
        <td>2</td>
        <td>alice</td>
        <td>18</td>
        <td>女</td>
        <td>
            <a href="javascript:;">修改</a>
            <a href="javascript:;">删除</a>
        </td>
    </tr>
    <tr>
        <td><input type="checkbox" name="students"></td>
        <td>3</td>
        <td>jack</td>
        <td>19</td>
        <td>男</td>
        <td>
            <a href="javascript:;">修改</a>
            <a href="javascript:;">删除</a>
        </td>
    </tr>
    <tr>
        <td><input type="checkbox" name="students"></td>
        <td>4</td>
        <td>tom</td>
        <td>20</td>
        <td>男</td>
        <td>
            <a href="javascript:;">修改</a>
            <a href="javascript:;">删除</a>
        </td>
    </tr>
</table>

</body>
</html>